package com.lin.manager.controller.notice;


import com.lin.manager.aop.Log;
import com.lin.manager.common.enums.LogEnum;
import com.lin.manager.common.req.QueryPage;
import com.lin.manager.common.resp.R;
import com.lin.manager.notice.model.vo.NoticeVO;
import com.lin.manager.notice.service.NoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @作者: 林江
 * @创建时间: 2024-04-10 19:11:15
 * @功能:
 */
@Api(tags = "通知公告")
@RestController
@RequestMapping("notice")
public class NoticeController {

    @Autowired
    NoticeService noticeService;

    @ApiOperation("通知公告 - 分页查询本人创建的通知公告")
    @Log(module = "通知公告", descipt = "分页查询我创建的通知公告", type = LogEnum.SELECT)
    @GetMapping("listMyCreatePage")
    public R listPage(QueryPage page) {
        return R.ok(noticeService.listCreatePage(page));
    }

    @ApiOperation("通知公告 - 分页查询本人接收的通知公告")
    @Log(module = "通知公告", descipt = "分页查询我接收的通知公告", type = LogEnum.SELECT)
    @GetMapping("listMyRecivePage")
    public R listRecivePage(QueryPage page) {
        return R.ok(noticeService.listRecivePage(page));
    }

    @ApiOperation("通知公告 - 查询未读消息数量")
    @Log(module = "通知公告", descipt = "查询未读消息", type = LogEnum.SELECT)
    @GetMapping("unread")
    public R unread() {
        return R.ok(noticeService.unread());
    }

    @ApiOperation("通知公告 - 添加")
    @Log(module = "通知公告", descipt = "添加通知公告", type = LogEnum.INSERT)
    @PostMapping("add")
    public R add(@RequestBody NoticeVO vo) {
        noticeService.add(vo);
        return R.ok();
    }

    @ApiOperation("通知公告 - 修改")
    @Log(module = "通知公告", descipt = "修改通知公告", type = LogEnum.UPDATE)
    @PostMapping("update")
    public R update(@RequestBody NoticeVO vo) {
        noticeService.update(vo);
        return R.ok();
    }

    @ApiOperation("通知公告 - 删除")
    @Log(module = "通知公告", descipt = "删除通知公告", type = LogEnum.DELETE)
    @DeleteMapping("delete")
    public R del(Long[] id) {
        noticeService.del(id);
        return R.ok();
    }

    @ApiOperation("通知公告 - 详情")
    @ApiImplicitParam(name = "sign", value = "1-已读", paramType = "path")
    @Log(module = "通知公告", descipt = "通知公告详情", type = LogEnum.SELECT)
    @GetMapping("/{sign}/getById")
    public R getById(@PathVariable("sign") Integer sign, Long id) {
        return R.ok(noticeService.getById(id, sign));
    }

    @ApiOperation("通知公告 - 发送")
    @Log(module = "通知公告", descipt = "发送通知公告", type = LogEnum.INSERT)
    @GetMapping("send")
    public R send(Long id) {
        noticeService.send(id);
        return R.ok();
    }
}
